CORONADO ENTERPRISES C++ TUTOR This documentation and the accompanying software, including all of the example C++ programs and text files, are protected under United States copyright law to protect them from unauthorized commercialization. You are permitted to make archival copies of the software solely for the purpose of backing-up your copy of the distribution disk and protecting your investment from loss. You are permitted to use this software on as many computers as you have legal access to provided it is not in use on more than one computer at a time. As the registered purchaser of this software, you are permitted to use portions of any of the example programs for inclusion in your own software and will not be required to pay any royalties or fees for any distribution. WARRANTY The diskette and the accompanying documentation are warranted to be free of defects in materials and workmanship for a period of 60 days from purchase. The warranty is limited to replacement of any or all defective material. Coronado Enterprises will not be responsible for any loss of profit or any other commercial damage due to the use of this tutorial or the information contained within it. Gordon Dodrill - May 15, 1994 Copyright (c) 1989, 1990, 1992, 1994 Coronado Enterprises Coronado Enterprises 12501 Coronado Ave NE Albuquerque, New Mexico 87122 C++ TUTORIAL - TABLE OF CONTENTS Introduction Page I-1 Chapter 1 - Simple Things Page 1-1 CONCOM.CPP Constants and comments 1-1 SCOPEOP.CPP Scope operator 1-2 MESSAGE.CPP The stream library 1-3 FSTREAM.CPP File streams 1-6 VARDEF.CPP Variable definitions 1-6 Chapter 2 - Compound Types Page 2-1 ENUM.CPP The enumerated type 2-1 STRUCTUR.CPP The structure 2-1 CLASS1.CPP The class 2-2 UNIONEX.CPP The union 2-3 TYPECONV.CPP Type conversions 2-3 Chapter 3 - Pointers Page 3-1 POINTERS.CPP Using Pointers 3-1 NEWDEL.CPP New and delete operators 3-2 FUNCPNT.CPP Function pointers 3-4 Chapter 4 - Functions Page 4-1 PROTYPE1.CPP Using prototypes 4-1 PROTYPE2.CPP Using prototypes 4-3 PASSREF.CPP Pass by reference 4-4 DEFAULT.CPP Parameter defaults 4-5 VARARGS.CPP Variable number of arguments 4-6 OVERLOAD.CPP Overloading function names 4-7 Chapter 5 - Encapsulation Page 5-1 OPEN.CPP No information hiding 5-1 CLAS.CPP Information hiding 5-2 OPENPOLE.CPP Corruptible data 5-6 CLASPOLE.CPP Protected data 5-7 CONSPOLE.CPP Constructors and destructors 5-9 BOXES1.CPP All in one file 5-10 BOX.H Box interface 5-11 BOX.CPP Box implementation 5-11 BOXES2.CPP Using the box class 5-12 DATE.H The date class header 5-15 DATE.CPP The date implementation 5-15 USEDATE.CPP Using the date class 5-16 Chapter 6 - More encapsulation Page 6-1 OBJARRAY.CPP An Array of objects 6-1 OBJSTRNG.CPP An object with a string 6-3 OBJINTPT.CPP An object with a pointer 6-4 OBJDYNAM.CPP Dynamic allocation of objects 6-5 OBJLIST.CPP Embedded pointers 6-6 OBJLINK.CPP Linked list of objects 6-7 NESTING.CPP Nested classes 6-8 OPOVERLD.CPP Operator overloading 6-9 FUNCOVER.CPP Function name overloading 6-11 DEFMETHS.CPP Default methods 6-12 PHRASE.H Inline example 6-14 PHRASE.INL Inline example 6-14 USEPHRAS.CPP Inline example 6-15 TIME.H The time class header 6-15 TIME.CPP The time implementation 6-15 USETIME.CPP Using the time class 6-15 Chapter 7 - Inheritance Page 7-1 VEHICLE.H Vehicle interface 7-1 VEHICLE.CPP Vehicle implementation 7-2 TRANSPRT.CPP Using the vehicle class 7-2 CAR.H Car interface 7-2 CAR.CPP Car implementation 7-4 TRUCK.H Truck interface 7-4 TRUCK.CPP Truck implementation 7-5 ALLVEHIC.CPP Use of car, truck, & vehicle 7-5 NEWDATE.H The newdate class header 7-7 NEWDATE.CPP The newdate implementaion 7-7 TRYNDATE.CPP Using the newdate class 7-8 Chapter 8 - More inheritance Page 8-1 INHERIT1.CPP Using public 8-1 INHERIT2.CPP Omitting public 8-2 INHERIT3.CPP Intra class messages 8-3 INHERIT4.CPP Without protected 8-4 INHERIT5.CPP Using protected 8-5 INHERIT6.CPP Using Constructors 8-5 INHERIT7.CPP Arrays and pointers 8-5 Chapter 9 - Multiple Inheritance Page 9-1 MULTINH1.CPP Multiple inheritance 9-2 MULTINH2.CPP Duplicate method names 9-3 MULTINH3.CPP Duplicate variable names 9-4 DATETIME.H Datetime class header 9-4 USEDTTM.CPP Using the datetime class 9-6 TEMPLAT1.CPP Simple template example 9-7 TEMPLAT2.CPP Strings template example 9-7 TEMPLAT3.CPP Class template example 9-8 Chapter 10 - Virtual functions Page 10-1 VIRTUAL1.CPP The starting point 10-1 VIRTUAL2.CPP Adding virtual 10-2 VIRTUAL3.CPP Using pointers to subclasses 10-3 VIRTUAL4.CPP Using virtual 10-3 VIRTUAL5.CPP Using pointers to parent class 10-4 VIRTUAL6.CPP True virtual functions 10-5 Chapter 11 - More Virtual Functions Page 11-1 PERSON.H Person header 11-1 PERSON.CPP Person implementation 11-1 SUPERVSR.H Personnel header 11-2 SUPERVSR.CPP Personnel implementation 11-2 EMPLOYEE.CPP A simple user program 11-3 ELEMLIST.H Linked list header 11-3 ELEMLIST.CPP Linked list implementation 11-4 EMPLOYE2.CPP A better user program 11-5 APPFRAM1.CPP Application framework 11-6 APPFRAM2.CPP Application framework 11-7 Chapter 12 - Flyaway adventure game Page 12-1 FLYAWAY.EXE Flyaway executable 12-1 FLYAWAY.H Global definitions 12-2 CLOCK.H Clock header 12-3 CLOCK.CPP Clock implementation 12-3 WORDS.H Command parsing header 12-3 WORDS.CPP Command parsing code 12-3 ITEMS.H Moveable items header 12-4 ITEMS.CPP Items implementation 12-4 SCHEDULE.H Scheduler header 12-5 SCHEDULE.CPP Scheduler implementation 12-5 LOCATION.H Locations header 12-6 LOCATION.CPP Locations implementation 12-6 MESSAGE.TXT String messages 12-7 FLYAWAY.CPP Main program 12-7 MAP.H Airport map header 12-8 MAP.CPP Airport map implementation 12-8 ABOUT THE AUTHOR ----------------------------------------------------------------- The author of this tutorial began programming in 1961 using FORTRAN on an IBM 1620. Since then, most of his career has been involved with designing digital logic for satellite application. In 1983, being somewhat burned out with logic design, he began a study of some of the more modern programming languages and has since made a complete career shift to software development. After learning Pascal, C was studied, followed by Modula-2 and Ada, and more recently C++. Rather than simply learning the syntax of each new language, modern methods of software engineering were studied and applied to effectively utilize the languages. He is currently employed by a large research and development laboratory where he continues to study, teach, and apply the newer programming languages.